<template>
  <div class="login-container">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
      <h3 class="title">商城管理系统</h3>
      <el-form-item prop="username">
        <el-input v-model="loginForm.username" placeholder="用户名" type="text">
          <i slot="prefix" class="el-icon-user"></i>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="loginForm.password" placeholder="密码" type="password">
          <i slot="prefix" class="el-icon-lock"></i>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button :loading="loading" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
          登录
        </el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="text" @click="handleRegister">注册账号</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'AdminLogin',
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      },
      loading: false
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          // 模拟登录成功
          setTimeout(() => {
            this.loading = false
            // 使用路由导航到 dashboard 页面
            this.$router.push('/dashboard')
            // 显示登录成功提示
            this.$message.success('登录成功')
          }, 1000)
        }
      })
    },
    handleRegister() {
      // TODO: 跳转到注册页面
      this.$message.info('注册功能开发中...')
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2d3a4b;

  .login-form {
    width: 400px;
    padding: 30px;
    background: #fff;
    border-radius: 6px;

    .title {
      text-align: center;
      margin-bottom: 30px;
      font-size: 26px;
      color: #333;
    }

    .el-input {
      height: 40px;
      input {
        height: 40px;
        padding-left: 35px;
      }
    }

    .el-icon-user,
    .el-icon-lock {
      padding: 0 5px;
      color: #889aa4;
    }
  }
}
</style>